import React from 'react';
import { observer } from 'mobx-react';
import { WeaSelectOptionProps } from '../../../../stores/mobxTable/table';
import { WeaSelect } from "ecCom";

interface Props {
    value?: string;
    options?: WeaSelectOptionProps[];
    onChange?;
    detailtype?;
    viewAttr:string;
}
@observer
export default class Main extends React.Component<Props, any>{

    render() {
        const props = this.props;
        let {value,viewAttr} = props;
        const options=props.options||[];
        const valueSpans=options.filter(item=>{return (','+value+',').indexOf(','+item.key+',')>-1});
        return (
            <div style={{float:'left'}}>
            {viewAttr=='2'?<WeaSelect
                    {...props}
                    viewAttr={viewAttr}
                    detailtype={props.detailtype}
                    options={options}
                    value={value}
                    onChange={props.onChange}
                    supportCancel
                />:valueSpans.map((item,index)=>{
                    let returnStr=item.showname;
                    if(index<(valueSpans.length-1)){
                        returnStr+=',';
                    }
                    return returnStr;
                })}
                
            </div>
        )
    }
}
